var mysql = require('mysql')
const { mysql: config } = require('../config')
var TEST_DATABASE = config.db

var pool = mysql.createPool({
    connectionLimit: 10,
    host: config.host,
    port: config.port,
    user: config.user,
    database: config.db,
    password: config.pass,
})

module.exports = (sql) => {
    return new Promise((resolve, reject) => {
        pool.getConnection((err, connection) => {
            if (err) {
                reject(err)
            } else {
                connection.query(sql, (err, results, fields) => {
                    connection.release()
                    if (err) {
                        reject(err)
                    } else {
                        resolve(results)
                    }
                })
            }
        })
    })
}
